//
//  UIView+CustomBadge.m
//  meets-ios
//

//

#import "UIView+CustomBadge.h"
#import <M13BadgeView.h>
#import <objc/runtime.h>

@implementation UIView (CustomBadge)

- (M13BadgeView *)badgeView {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setBadgeView:(M13BadgeView *)badgeView {
    objc_setAssociatedObject(self, @selector(badgeView), badgeView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)addBadgeNumber:(NSInteger)number {
    if (!self.badgeView) {
        M13BadgeView *badgeView = [[M13BadgeView alloc] initWithFrame:CGRectMake(0, 0, ADAPTER_WIDTH_BASED6(19.f), ADAPTER_WIDTH_BASED6(19.f))];
        badgeView.font = [UIFont systemFontOfSize:12];
        [self addSubview:badgeView];
        self.badgeView = badgeView;
    }
    self.badgeView.text = [NSString stringWithFormat:@"%@", @(number)];
    WeakSelf(wself);
    [self.badgeView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(wself.mas_right);
        make.top.equalTo(wself.mas_top);
        make.size.mas_equalTo(wself.badgeView.size);
    }];
}

@end
